package com.elibrary;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import nimo.elibrary.json.model.book.Book;

/**
 * Created with IntelliJ IDEA.
 * User: Enkuso
 * Date: 1/23/13
 * Time: 11:33 AM
 * To change this template use File | Settings | File Templates.
 */
public class HistorylistAdapter extends ArrayAdapter<Book> {
    Context context;
    int layoutResourceId;
    Book data[] = null;
    public HistorylistAdapter(Context context, int textViewResourceId, Book[] data) {
        super(context, textViewResourceId, data);
        this.context = context;
        this.layoutResourceId = textViewResourceId;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;

        if(row == null) {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
        }

        TextView title=(TextView)row.findViewById(R.id.tvTitle);
        TextView shortInfo=(TextView)row.findViewById(R.id.tvShortInfo);
        TextView viewDate=(TextView)row.findViewById(R.id.tvViedDate);
        ImageView cover=(ImageView)row.findViewById(R.id.ivCover);

        Book book = data[position];

        title.setText(book.title);
        shortInfo.setText(book.introduction);
        viewDate.setText(book.viewed_at);
        ((BookstoreApplication)context.getApplicationContext()).imageLoader.DisplayImage(book.cover, cover);
        row.setTag(book.id);

        return row;
    }
}
